﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec.NTD
{
    public partial class ConfirmUungVien : System.Web.UI.Page
    {
        public int HoSoId { get; set; }
        public int tuyenDungId { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Session["NTD"] == null)
            {
                Response.Redirect("/nha-tuyen-dung.html");
            }
            if(Request.QueryString["id"]!=null)
            {
                HoSoId = int.Parse(Request.QueryString["id"].Split('-')[0]);
                tuyenDungId = int.Parse(Request.QueryString["id"].Split('-')[1]);
            }
            if(!IsPostBack)
            {
                LoadData();
            }
        }
        public void LoadData()
        {
            DAL.UserTuyenDung user = BLL.TuyenDung.UserHelper.Get_UserEmail(Session["NTD"].ToString());
            DAL.tbl_TD_TuyenDung tuyendung = BLL.TuyenDung.DangTuyenHelper.Get_TinTuyenDung(tuyenDungId);
            if(tuyendung!=null)
            {
                lbVitriungtuyen.Text = tuyendung.ChucDanh;
                txtNguoiGui.Text =user.NguoiLienHe+" - "+ user.TenCongTy;                
            }
            DAL.tbl_HS_HoSo hso = BLL.TuyenDung.ViewHelper.Get_HoSoId(HoSoId);
            if(hso!=null)
            {
                txtNguoiNhan.Text = hso.User.UserName;
                txtEmailNguoiNhan.Text = hso.Email;
            }
        }
        protected void btCancel_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        protected void btSend_Click(object sender, EventArgs e)
        {
            string email = System.Configuration.ConfigurationManager.AppSettings["mail"];
            string MK = System.Configuration.ConfigurationManager.AppSettings["mailpassword"];

            string noidung = "-Chào <b>" + txtNguoiNhan.Text + "</b><br/>"
                             + "-Bạn có một Email từ nhà tuyển dụng: " + txtNguoiGui.Text + "<br/>"
                             + "-Với vị trí ứng tuyển: " + lbVitriungtuyen.Text+"<br/>"
                             +CKENoiDung.Text;
            MailHelper.SendMail1(txtEmailNguoiNhan.Text, "Svcareer: " + txtTieuDe.Text, noidung, email, MK);
            Response.Redirect("/nha-tuyen-dung/danh-sach-ung-vien.html");
        }
    }
}